﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Web.UI;

namespace Duson.Controls.Pager
{
    /// <summary>
    /// 文本框跳转方式
    /// </summary>
    public class SkipType_TextBox : SkipTypeAbstract
    {
        public override void CreateControls(HtmlTextWriter writer)
        {
            // 控件ID
            string txtPageID = MyPager.UniqueID + "_" + ConstParams.PageTextID_Suffix;
            string btnGoPageID = MyPager.UniqueID + "_" + ConstParams.GoButtonID_Suffix;

            // textbox
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "30px");
            writer.AddAttribute(HtmlTextWriterAttribute.Value, MyPager.PageIndex.ToString());
            writer.AddAttribute(HtmlTextWriterAttribute.Name, txtPageID);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, txtPageID);

            writer.AddAttribute("onkeypress", "return TextPage_keydown(event, '" + btnGoPageID + "');");
            writer.RenderBeginTag(HtmlTextWriterTag.Input);
            writer.RenderEndTag();

            // button
            writer.AddAttribute(HtmlTextWriterAttribute.Type, MyPager.PagingMethod == PagingMethod.Url ? "Button" : "Submit");
            writer.AddAttribute(HtmlTextWriterAttribute.Name, btnGoPageID);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, btnGoPageID);
            writer.AddAttribute(HtmlTextWriterAttribute.Value, MyPager.GoButtonText);

            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, MyPager.PagingMethod == PagingMethod.Url ? "UrlPage('" + ConstParams.Url_Params + "', document.getElementById('" + txtPageID + "').value);" : "__doPostBack('" + MyPager.ClientID + "', document.getElementById('" + txtPageID + "').value)");
            writer.RenderBeginTag(HtmlTextWriterTag.Input);
            writer.RenderEndTag();
        }

    }
}
